/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package imat;

import java.awt.Dimension;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.swing.JPanel;
import se.chalmers.ait.dat215.project.ShoppingCart;

/**
 *
 * @author Gustav
 */
public class SavedTrolleysPresenter {
    private SavedTrolleysView savedTrolleysView;

    public SavedTrolleysPresenter (SavedTrolleysView view) {
        savedTrolleysView = view;
    }

    public void fillPanel() {
        JPanel panel = savedTrolleysView.getTrolleysPanel();

        panel.removeAll();

        Map<String,ShoppingCart> carts = DataHandler.getInstance().getSavedCarts();
        Set<Entry<String,ShoppingCart>> cartSets = carts.entrySet();
        for (Entry<String,ShoppingCart> cart : cartSets) {
            TrolleyItemView view = new TrolleyItemView();
            view.setShoppingCart(cart.getValue(), cart.getKey());
            panel.add(view);
        }


        // Scrollbar fix
        JPanel scrollPanel = savedTrolleysView.getScrollPanel();
        scrollPanel.setPreferredSize(new Dimension(0, 200+cartSets.size()*50));
        scrollPanel.revalidate();

        panel.repaint();
        panel.revalidate();
    }

}
